package com.cynteka.cyfoman.core;

import com.cynteka.cyfoman.core.IPropertyResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

/**
 * User: Sergey
 * Date: 01.08.11
 * Time: 20:00
 */
public class XMLPropertyResolver implements IPropertyResolver {
    @Override
    public Object getProperty(Object object, String propertyName) {
        Object res = null;
        if (object instanceof Node) {
            Node node = (Node) object;
            NamedNodeMap attributes = node.getAttributes();
            res = attributes == null ? null : attributes.getNamedItem(propertyName);
        }
        if (res instanceof Attr) {
            Attr attr = (Attr) res;
            res = attr.getValue();
        }
        return res;
    }
}
